/*!
 * \file UapGenerator.h
 * \brief Generator for UAP state machine in Serving Gateway
 */

#ifndef SGW_UAP_GENERATOR_H
#define SGW_UAP_GENERATOR_H

#include "Generator.h"
#include "StateBase.h"
#include "UserContext.h"
#include "Timer.h"
#include "UAP.pb.h"
#include "UapGlobals.h"

namespace tsc
{
namespace sgw
{

/**
 * Generator implementation for UAP protocol in Serving Gateway
 */
class UapGenerator : public common::Generator
{
public:

	/**
	 * Creates new UapGenerator for handling new signaling connection with
	 * User Client
	 *
	 * \param context user context
	 * \param connectionId full 32-bit id of the connection
	 */
	UapGenerator(common::GeneratorEnvironment& ge,
			     UserContext* context,
			     uint32_t connectionId);

	virtual ~UapGenerator();

	static bool findGenerator(uint32_t connectionId, UapGenerator*& generator);

	/**
	 * Returns capabilities of a client side
	 */
	UserApplicationPart::ClientCapabilities* getCapabilities() const;

	/**
	 * Sets capabilities of a client side
	 */
	void setCapabilities(const UserApplicationPart::ClientCapabilities* capabilities);

	/**
	 * Gets UserContext associated with this generator
	 */
	UserContext* getContext() const;

	/**
	 * Returns ID of the UAP generator in client side - that is last 8 bits
	 * of the clientId used in UAP PDUs
	 *
	 * \return id of client's UAP generator
	 */
//	uint8_t getUserGeneratorId() const;

	/**
	 * Returns connection ID, that is combined clientId and user generator ID
	 */
	uint32_t getConnectionId() const;

    uint32_t getClientMediaPort() const;

    void setClientMediaPort(uint32_t clientMediaPort);

    uint32_t getMediaItemId() const;

    void setMediaItemId(uint32_t mediaItemId);

    uint32_t getServerMediaPort() const;

    void setServerMediaPort(uint32_t mediaServerPort);

    ProtocolsCommon::IpAddress* getServerMediaAddress() const;

    void setServerMediaAddress(ProtocolsCommon::IpAddress* ip);

    // TODO - implement these
    void startT643(unsigned long valueMs = T_643_VALUE);
    void cancelT643();

protected:
	UserContext* mpContext;
	UserApplicationPart::ClientCapabilities* mpCapabilities;
	uint32_t mConnectionId;
	uint32_t mMediaItemId;
	uint32_t mClientMediaPort;
	uint32_t mServerMediaPort;
	ProtocolsCommon::IpAddress* mpServerMediaAddress;

	common::Timer* mpT643;

private:
	static std::map<uint32_t, UapGenerator*> msGeneratorMap;
};

} // namespace sgw
} // namespace tsc

#endif // SGW_UAP_GENERATOR_H
